package com.neusoft.lohas.common.restTemplate.client;


public enum HandleStatusEnum {
	SUCCESS(ResponseCode.SUCCESS, ""),
	NO_CONTENT(ResponseCode.NO_CONTENT, "没有数据"),
	COMMON_ERROR(ResponseCode.COMMON_ERROR, "未知错误"),
	UNAUTHORIZED(ResponseCode.UNAUTHORIZED, "需要登录"),
	NEW_CELL(ResponseCode.NEW_CELL, "是一个新的cell"),
	SAVE_ERROR(ResponseCode.SAVE_ERROR, "保存错误"),
	NOT_EXIT(ResponseCode.NOT_EXIT, "不存在"),
	BE_BLOCKED(ResponseCode.BE_BLOCKED, "你已经被拉黑了"),
	DELETED(ResponseCode.DELETED, "已被删除"),
	FORBIDDEN(ResponseCode.FORBIDDEN, "没有操作权限"),
	ALREADY_EXIST(ResponseCode.ALREADY_EXIST, "已经存在"),
	CONFINICT(ResponseCode.CONFINICT, "和现有数据冲突");
	private final int statusCode;
	private final String desc;

	private HandleStatusEnum(int status, String desc) {
		this.statusCode = status;
		this.desc = desc;
	}

	public final int getStatusCode() {
		return statusCode;
	}

	public final String getDesc() {
		return desc;
	}

	public static HandleStatusEnum createFromCode(int code) {
		HandleStatusEnum[] enums = HandleStatusEnum.values();
		for (HandleStatusEnum handleStatusEnum : enums) {
			if (handleStatusEnum.getStatusCode() == code)
				return handleStatusEnum;
		}
		return null;
	}

	public boolean haveError() {
		return (statusCode / 100) > 2;
	}

}
